package com.bbu.javaexam.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.bbu.javaexam.domain.Admin;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @author Alex
 * @version 1.0.0
 * @ClassName AdminMapper.java
 * @Description TODO
 */
@Mapper
public interface AdminMapper extends BaseMapper<Admin> {
    /**
     * @throws
     * @title 查找全部管理员
     * @description
     * @author Alex
     * @updateTime 2021/12/5 14:24
     */
    @Select("select adminName,sex,tel,email,cardId,role from admin")
    public List<Admin> findAll();

    /**
     * @throws
     * @title 通过Id查找指定管理员
     * @description
     * @author Alex
     * @updateTime 2021/12/5 14:24
     */
    @Select("select adminName,sex,tel,email,cardId,role from admin where adminId = #{adminId}")
    public Admin findById(Integer adminId);

    /**
     * @throws
     * @title 通过ID删除管理员用户
     * @description
     * @author Alex
     * @updateTime 2021/12/5 14:24
     */
    @Delete("delete from admin where adminId = #{adminId}")
    public int deleteById(int adminId);

    /**
     * @throws
     * @title 编辑保存指定管理员
     * @description
     * @author Alex
     * @updateTime 2021/12/5 14:25
     */
    @Update("update admin set adminName = #{adminName},sex = #{sex}," +
            "tel = #{tel}, email = #{email},pwd = #{pwd},cardId = #{cardId},role = #{role} where adminId = #{adminId}")
    public int update(Admin admin);

    /**
     * @throws
     * @title 新增管理员
     * @description
     * @author Alex
     * @updateTime 2021/12/5 14:26
     */
    @Options(useGeneratedKeys = true, keyProperty = "adminId")
    @Insert("insert into admin(adminName,sex,tel,email,pwd,cardId,role) " +
            "values(#{adminName},#{sex},#{tel},#{email},#{pwd},#{cardId},#{role})")
    public int add(Admin admin);
}
